package com.woniu.humanresource.service.impl;

import com.woniu.humanresource.dao.LecturerDao;
import com.woniu.humanresource.entity.Lecturer;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.service.LecturerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LecturerServiceImpl implements LecturerService {

    @Resource
    LecturerDao lecturerDao;

    @Override
    public void insertLecturer(Lecturer lecturer) {
        lecturerDao.insertLecturer(lecturer);
    }

    @Override
    public PageBean<Lecturer> selectLecturerCondition(Lecturer lecturer, int pageIndex, int pageSize) {
        // 条件查询讲师集合
        List<Lecturer> lecturers = lecturerDao.selectLecturerCondition(lecturer, pageIndex, pageSize);
        // 封装pagebean对象
        PageBean<Lecturer> pageBean = new PageBean<>();
        pageBean.setBeanList(lecturers);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setBeginEnd();
        pageBean.setTotalRecord(lecturerDao.selectLecturerConditionCount(lecturer));

        return pageBean;
    }

    @Override
    public void updateLecturer(Lecturer lecturer) {
        lecturerDao.updateLecturer(lecturer);
    }

    @Override
    public void deleteLecturer(int lid) {
        lecturerDao.deleteLecturer(lid);
    }

    @Override
    public List<Lecturer> getAllLecturer() {
        List<Lecturer> lecturers = lecturerDao.selcetAllLecturer();
        return lecturers;
    }
}
